import '../public.dart';

class AuthApi {
  /// 手机客户端用户登录
  /// /login/loginByName
  static Future<BaseResponse<LoginResponseDto>> login(LoginDto params) async {
    final response = await HttpUtil().request(
      '/login/loginByName',
      method: 'POST',
      data: params.toJson(),
    );
    return BaseResponse<LoginResponseDto>.fromJson(
      response,
      fromJsonT: (json) => LoginResponseDto.fromJson(json as Map<String, dynamic>),
    );
  }

  /// 后台账号登录
  /// /login/backend/loginByName
  static Future<BaseResponse<BackendLoginResponseDto>> backendLogin(
    BackendLoginDto params,
  ) async {
    final response = await HttpUtil().request(
      '/login/backend/loginByName',
      method: 'POST',
      data: params.toJson(),
    );
    return BaseResponse<BackendLoginResponseDto>.fromJson(
      response,
      fromJsonT: (json) => BackendLoginResponseDto.fromJson(json as Map<String, dynamic>),
    );
  }

  /// 登出
  /// /login/logout
  static Future<BaseResponse<void>> logout() async {
    final response = await HttpUtil().request('/login/logout', method: 'GET');
    return BaseResponse<void>.fromJson(response);
  }
}
